package com.example.q_kang.hhh.home;

import com.example.q_kang.hhh.api.JsonCallBack;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.base.BasePresenter;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.TeamCommonData;
import com.example.q_kang.hhh.api.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/04/09
 */
class TeamManagerPresenter extends BasePresenter<TeamManagerFragment> {

    public void getTeamCommonData() {
        httpService.getTeamCommonData(0)
                .tag(this)
                .execute(new JsonCallBack<HttpData<TeamCommonData>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TeamCommonData>> response) {
                        HttpData<TeamCommonData> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.getCommonDataSuccess(body.getData());
                        }
                    }

                    @Override
                    public void onStart(Request<HttpData<TeamCommonData>, ? extends Request> request) {
                        super.onStart(request);
                        mView.showLoading();
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }


    public Flowable<List<TeamCommonData.TeamData>> getTeamList(int page) {
        return httpService.getTeamCommonData(page)
                .tag(this)
                .converter(new JsonConverter<HttpData<TeamCommonData>>() {
                })
                .adapt(new FlowableBody<>())
                .map(listHttpData -> listHttpData.getData().getTjrNum());
    }

}
